﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using dao;
using common;
namespace GTVAccountingSystem.view.form
{
    public partial class frmMessages : Form
    {
        PopupManagerDAO popupManagerDAO = new PopupManagerDAO();
        DataTable dt;
        String status = "";
        public frmMessages()
        {
            InitializeComponent();
        }
        private void tabForgetPassword_Click(object sender, EventArgs e)
        {
            
            rdbAll.Checked = true;
            txtUsername.Text = "";
            setRadioButton();
            loadTableForgetPassword();
            
        }
        public void loadTableFeedback()
        {
            String actions = Constant.DR_ACTIONS_VARIABLE["varFeedback"].ToString();
            dt = popupManagerDAO.getAllPopupByConditionOfForgetPasswordOrFeedback(status, txtUsername.Text.Trim(), actions);
            DataTable dtLoad = dt;
            dtLoad.Columns.Remove("ID");
            dtLoad.Columns.Remove("Contents");
            dgvForgetPassword.DataSource = dtLoad;
        }
        public void loadTableForgetPassword()
        {
            String actions = Constant.DR_ACTIONS_VARIABLE["varForgetPassword"].ToString();
            dt = popupManagerDAO.getAllPopupByConditionOfForgetPasswordOrFeedback(status, txtUsername.Text.Trim(), actions);
            DataTable dtLoad = dt;
            dtLoad.Columns.Remove("ID");
            dtLoad.Columns.Remove("Subject");
            dtLoad.Columns.Remove("Contents");
            dgvForgetPassword.DataSource = dtLoad;
        }
        private void tabFeedback_Click(object sender, EventArgs e)
        {
            rdbAll.Checked = true;
            txtUsername.Text = "";
            setRadioButton();
            loadTableFeedback();
        }
        public void setRadioButton()
        {
            if (rdbAll.Checked == true)
            {
                rdbRead.Checked = false;
                rdbUnread.Checked = false;
                status = "";
            }
            else if (rdbRead.Checked == true)
            {
                rdbAll.Checked = false;
                rdbUnread.Checked = false;
                status = "1";
            }
            else
            {
                rdbAll.Checked = false;
                rdbRead.Checked = false;
                status = "0";
            }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            setRadioButton();
            if (tabMessageControl.SelectedIndex == 0)
                loadTableFeedback();
            else
                loadTableForgetPassword();
        }

        private void dgvFeedback_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            rtbContents.Text = dt.Rows[e.RowIndex]["Contents"].ToString();
            popupManagerDAO.viewFeedbackContents(dt.Rows[e.RowIndex]["ID"].ToString());
        }
    }
}
